package com.itsitio.registeradmin.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "paises")
public class Country {
//public class Country extends MappedEntity {

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name = "idx")
	private Integer id;
	
	//Nombre Pais	
	@Column(name = "descripcion")
	private String name;

	//Numero	
	@Column(name = "numero")
	private Integer number;
	
	//Region	
	@Column(name = "region")
	private String region;

	//Tel	
	@Column(name = "tel")
	private Integer phoneRegion;
	
	//@OneToMany(fetch=FetchType.EAGER, cascade = CascadeType.ALL, mappedBy="country")
	@OneToMany(fetch=FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinColumn(name="idxpais")
	private List<Province> provinces;

	//@ManyToMany(cascade = CascadeType.ALL, mappedBy = "countries")
    //@JoinTable(name = "xxxportalesXcomunidadesXpaises")
	//@ManyToMany(cascade = CascadeType.ALL, mappedBy = "countries")
	
	//@ManyToMany(mappedBy = "countries", fetch = FetchType.LAZY)	
	
	/*
	@ManyToMany(targetEntity=com.itsitio.registeradmin.model.Portal.class,
	        cascade={CascadeType.PERSIST, CascadeType.MERGE})	
    @JoinTable(name = "xxxportalesXcomunidadesXpaises",
        joinColumns = {@JoinColumn(name = "IdxPais")},
        inverseJoinColumns = {@JoinColumn(name = "IdxPortal")})	
	 */
	@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, mappedBy = "countries", targetEntity = com.itsitio.registeradmin.model.Portal.class)
    private List<Portal> portals;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getNumber() {
		return number;
	}

	public void setNumber(Integer number) {
		this.number = number;
	}

	public String getRegion() {
		return region;
	}

	public void setRegion(String region) {
		this.region = region;
	}

	public Integer getPhoneRegion() {
		return phoneRegion;
	}

	public void setPhoneRegion(Integer phoneRegion) {
		this.phoneRegion = phoneRegion;
	}

	public List<Province> getProvinces() {
		return provinces;
	}

	public void setProvinces(List<Province> provinces) {
		this.provinces = provinces;
	}

	public List<Portal> getPortals() {
		return portals;
	}

	public void setPortals(List<Portal> portals) {
		this.portals = portals;
	}	

}
